import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule, Routes } from '@angular/router';

import { AppComponent } from './app.component';
import { ZeroComponent } from './zero/zero.component';
import { PinkComponent } from './pink/pink.component';
import { HeroComponent } from './hero/hero.component';
import { NotFindComponent } from './not-find/not-find.component';

const routes: Routes = [
  {
    path: '',
    redirectTo: '/index',
    // 这里需要开启完整匹配
    pathMatch: 'full',
  },
  {
    // path不能以/开头
    path: 'index',
    component: ZeroComponent,
  },
  {
    // 路由传参
    path: 'pink/:id',
    component: PinkComponent,
  },
  {
    path: 'hero',
    component: HeroComponent,
  },
  // 匹配任意url
  { path: '**', component: NotFindComponent }
];
@NgModule({
  declarations: [AppComponent, ZeroComponent, PinkComponent, HeroComponent, NotFindComponent],
  imports: [
    BrowserModule,
    FormsModule,
    HttpClientModule,
    // 导入路由模块应用路由字典
    // 为跟模块使用
    RouterModule.forRoot(routes),
  ],
  providers: [],
  bootstrap: [AppComponent],
})
export class AppModule {}
